import 'package:locker/home.dart';
import 'package:flutter/material.dart';
import 'color_control.dart';
import 'package:provider/provider.dart';
import 'model.dart';
import 'package:page_transition/page_transition.dart';

class MyRoundedButton extends StatelessWidget {
  final String lockerOpenMessage =
      '很好！这次我更改了密码，你还能破解吗？';
  final String lockerStillLockedMessage = '密码错误!';

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(bottom: 18),
      child: RawMaterialButton(
        elevation: 0,
        enableFeedback: false,
        onPressed: () {
          LockerState lockerState = context.read<Locker>().unlock();
          if (lockerState == LockerState.unlocked) {
            Scaffold.of(context).showSnackBar(SnackBar(
              content: Text(
                lockerOpenMessage,
                style: TextStyle(
                    color: kLight,
                    fontWeight: FontWeight.w600,
                    fontSize: 16,
                    fontFamily: 'Quicksand'),
              ),
              duration: Duration(milliseconds: 2000),
              backgroundColor: kDark,
              shape: RoundedRectangleBorder(
                  borderRadius:
                      BorderRadius.vertical(top: Radius.circular(20))),
            ));
            Navigator.of(context).pushReplacement(PageTransition(
                child: MyAppHome(),
                type: PageTransitionType.fade,
                duration: Duration(milliseconds: 2000)));
          } else if (lockerState == LockerState.locked) {
            Scaffold.of(context).showSnackBar(SnackBar(
              content: Text(
                lockerStillLockedMessage,
                style: TextStyle(
                    color: kLight,
                    fontWeight: FontWeight.w600,
                    fontSize: 16,
                    fontFamily: 'Quicksand'),
              ),
              duration: Duration(milliseconds: 650),
              backgroundColor: kDark,
              shape: RoundedRectangleBorder(
                  borderRadius:
                      BorderRadius.vertical(top: Radius.circular(20))),
            ));
          }
        },
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(70)),
        fillColor: kDark,
        child: SizedBox(
          width: MediaQuery.of(context).size.width - 100,
          height: 80,
          child: Center(
            child: Icon(Icons.lock, color: kLight, size: 42),
          ),
        ),
      ),
    );
  }
}
